/*
 * Javlov - a Java toolkit for reinforcement learning with multi-agent support.
 * 
 * Copyright (c) 2009 Matthijs Snel
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov.policy;

import java.util.List;

import net.javlov.Action;
import net.javlov.NeuralNet;

/**
 * Policy from
 * 
 * Ackley D. E. & Littman M. (1990). Generalization and scaling in reinforcement learning.
 * In Touretzky D. S. (ed.), Advances of Neural Information Processing Systems – 2. San
 * Mateo, CA: Morgan Kaufmann.
 * 
 * Note: the learning part is not implemented yet.
 * 
 * @author Matthijs Snel
 *
 */
public final class CRBPPolicy extends NeuralPolicy.DiscreteBinary {

	//TODO implement learning part
	/**
	 * Stretchfactor v
	 */
	private double v;
	
	public CRBPPolicy(NeuralNet net, List<? extends Action> actionPool, double stretchFactor ) {
		super(net, actionPool);
		setStretchFactor(stretchFactor);
	}
	
	public double getStretchFactor() {
		return v;
	}
	
	public void setStretchFactor(double stretchFactor) {
		v = stretchFactor;
	}
	
	@Override
	protected Action getActionFromOutput(double[] output) {
		return super.getActionFromOutput( generateBinary(output) );
	}
	
	private double[] generateBinary(double output[]) {
		double out[] = new double[output.length];
		for ( int i = 0; i < out.length; i++ )
			out[i] = ((output[i] - 0.5) / v + 0.5 >= Math.random() ? 1 : 0);
		return out;
	}
}
